package com.zhaoyu.wemedia.controller;

import com.zhaoyu.apis.wemedia.WmMaterialControllerApi;
import com.zhaoyu.common.constants.WemediaConstants;
import com.zhaoyu.model.common.dtos.ResponseResult;
import com.zhaoyu.model.media.dtos.WmMaterialDto;
import com.zhaoyu.wemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController implements WmMaterialControllerApi {

    @Autowired
    private WmMaterialService wmMaterialService;

    @Override
    @PostMapping("/upload_picture") // json格式的数据
    public ResponseResult uploadImageWmMaterial(MultipartFile file) { // 测试的时候不要在请求头中添加Content-Type: application/json(切记！！！)
        return wmMaterialService.uploadImage(file);
    }

    @Override
    @RequestMapping("/find_picture") // json格式的数据
    public ResponseResult findImageWmMaterial(@RequestBody WmMaterialDto wmMaterialDto) {
        return wmMaterialService.findImage(wmMaterialDto);
    }

    @Override
    @GetMapping("/delete_picture/{id}") // rest风格
    public ResponseResult deleteImageWmMaterial(@PathVariable("id") Integer id) {
        return wmMaterialService.deleteImage(id);
    }

    /**
     * 是否收藏
     *  0：未收藏
     *  1：收藏
     */
    @Override
    @GetMapping("/cancel_collect/{id}") // rest风格
    public ResponseResult cancelCollectionWmMaterial(@PathVariable("id") Integer id) {
        return wmMaterialService.updateIsCollectionById(id, WemediaConstants.CANCEL_COLLECT_MATERIAL); // 未收藏
    }

    @Override
    @GetMapping("/collect/{id}") // rest风格
    public ResponseResult collectionWmMaterial(@PathVariable("id") Integer id) {
        return wmMaterialService.updateIsCollectionById(id, WemediaConstants.COLLECT_MATERIAL); // 收藏
    }

}